package cn.zktr.Personnel.controllers.zhouyongcong;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.zktr.Personnel.model.pojos.PerAudit;
import cn.zktr.Personnel.model.pojos.PerPmsStm;
import cn.zktr.Personnel.model.service.zhouyongcong.boolService;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.service.zhouyongcong.savePojosService;
import cn.zktr.Personnel.model.service.zhouyongcong.saveService;

@Controller
public class savaController {
	@Autowired
	private saveService ss;
	@Autowired
	private findService fs;
	@Autowired
	private boolService bl;
	@Autowired
	private savePojosService ms;
	
	@RequestMapping("aud_table")
	@ResponseBody
	public List<PerAudit> aud_table() {
		return fs.findAllAudit();
	}
	/**部门新增、业务新增、员工部门绑定
	 * @param deptname
	 * @param deptid
	 * @param empid
	 * @param depttext
	 * @param bunlxid
	 * @param bunsum
	 * @return
	 */
	@RequestMapping("dept_add")
	@ResponseBody
	public int dept_add(
			String deptname,//业务名称
			int deptid,//所属部门id
			int stmid,//负责人id
			int empid,//处理人id
			String depttext,//详情介绍
			int bunlxid,//业务类型
			int bunsum,//人数
			
			String[] potname,//职位名称
			int[] zjiid,//职级id
			int[] bzbsum,//员工数量
			int[] zjid//技能id
			) {
		//业务生成
		int ybun = ss.save_YBun_id(deptid,stmid,bunlxid,deptname,bunsum);
		//部门生成 并获得新增id
		int dept = ss.save_Dept_id(deptname,deptid,depttext);
		//业务详情表添加
		ss.save_Yywxq(ybun,stmid);
		
		String potzw = "组长";
		
		ss.save_Pot(bl.bool_Pot(deptname+potzw), 3, deptname+potzw);
		
		ss.save_Stm(stmid, bl.bool_Pot(deptname+potzw), dept);
		//部门管理生成
		ss.save_Mgm(dept,stmid,potzw);
		
		
		
		
		for(int v=0;v<potname.length;v++) {
			int pot = bl.bool_Pot(potname[v]);
			//职位生成
			ss.save_Pot(pot, zjiid[v], potname[v]);
			if(zjid[v]!=0) {
				//求职意向表
				ss.save_Walt(bl.bool_Walt(),pot, bzbsum[v], "对外", empid, stmid, dept, zjid[v], "1");
			}
			//部门职位表生成
			ss.save_Bzb(bl.bool_Bzb(dept, pot),dept, pot, bzbsum[v]);
		}
		return dept;
	}
	@RequestMapping("emp_upt")
	@ResponseBody
	public void emp_upt(int stmid,int potid,int deptid) {
		PerPmsStm pps = fs.findStmid(stmid);
		pps.setPerPmsPot(fs.findPotid(potid));
		pps.setPerPmsDept(fs.findDeptid(deptid));
		ms.modif_Stm(pps);
	}
//	//员工添加
//	@RequestMapping("emp_add")
//	@ResponseBody
//	public int emp_add(int ittid) {
//		PerRetItt prt =  fs.findIttid(ittid);
//		PerRetRse prr =  prt.getPerRetRse();
//		int emp = ss.save_Emp_id(prr.getRsename(),prr.getRsecard());
//		ss.save_Empdet(prr.getPerPmsSex(), emp,Integer.valueOf(prr.getRseage()), "汉族", "中国", new TimeStamp().byTimestamp(prr.getRsecard()), prr.getRsedizhi());
//		return 0;
////	}
}
